package com.wc.alorithm_blue_bridge._博弈论.单词博弈;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/30 1:59
 * @description https://www.lanqiao.cn/problems/18595/learning/?contest_id=193
 */
public class Main {
    /**
     * 思路：
     * 考虑什么情况下是最优选择
     * 如果对手的单词是以 'a' 开头的，此时我们既有 'a' 开头的单词 也有 'b' 开头的单词。
     * 此时我们选择以 'a' 开头的且大于 对于的字典序的 最小单词 输出是最优的
     * 对于对手来说也是同样的道理
     * 所以每个选手考虑的方式都是相同的: 先输出相同字母且大于对手的最小字典序的单词
     * <p>
     * 既然是这样，我们就可以直接模拟来判断结果
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = 26;
    static String[] a = new String[N];
    static String[] b = new String[N];
    static int n, m;


    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < n; i++) {
            a[i] = sc.next();
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.next();
        }
        String last = a[0];
        int i = 1, j = 0, order = 1;
        while (i < n && j < m) {
            if (order == 1) {
                char fc = b[j].charAt(0), lc = last.charAt(0);
                if (fc == lc + 1 || (fc == lc && b[j].compareTo(last) > 0)) last = b[j++];
                else {
                    j++;
                    continue;
                }
            } else {
                char fc = a[i].charAt(0), lc = last.charAt(0);
                if (fc == lc + 1 || (fc == lc && a[i].compareTo(last) > 0)) last = a[i++];
                else {
                    i++;
                    continue;
                }
            }
            order ^= 1;
        }
        // 最后一个的判断
        if (i == n && j < m && order == 1) {
            char fc = b[j].charAt(0), lc = last.charAt(0);
            if (fc == lc + 1 || (fc == lc && b[j].compareTo(last) > 0)) order ^= 1;

        }
        // 最后一个的判断
        if (j == m && i < n && order == 0) {
            char fc = a[i].charAt(0), lc = last.charAt(0);
            if (fc == lc + 1 || (fc == lc && a[i].compareTo(last) > 0)) order ^= 1;
        }
        if (order == 0) out.println("Q");
        else out.println("L");

        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
